package com.ft.admix.gdt.adapter;

import android.app.Activity;

import com.bytedance.sdk.openadsdk.AdSlot;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.bytedance.sdk.openadsdk.TTFullScreenVideoAd;
import com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot;
import com.ft.admix.ad.MixCustomInterstitialAdapter;
import com.ft.admix.config.AdConfig;
import com.qq.e.ads.interstitial2.UnifiedInterstitialAD;
import com.qq.e.ads.interstitial2.UnifiedInterstitialADListener;
import com.qq.e.ads.interstitial2.UnifiedInterstitialMediaListener;
import com.qq.e.comm.util.AdError;

public class InterstitialAdLoader extends MixCustomInterstitialAdapter {
    private UnifiedInterstitialAD interstitialAD;

    @Override
    protected void loadNetworkAd(Activity context, AdConfig config) {
        interstitialAD = new UnifiedInterstitialAD(context, config.getAdId(), new UnifiedInterstitialADListener() {
            @Override
            public void onADReceive() {
                callLoadSuccess(interstitialAD.getECPM());
                interstitialAD.setMediaListener(new UnifiedInterstitialMediaListener() {
                    @Override
                    public void onVideoInit() {

                    }

                    @Override
                    public void onVideoLoading() {

                    }

                    @Override
                    public void onVideoReady(long l) {

                    }

                    @Override
                    public void onVideoStart() {
                        callInterstitialVideoStart();
                    }

                    @Override
                    public void onVideoPause() {

                    }

                    @Override
                    public void onVideoComplete() {
                        callInterstitialVideoComplete();
                    }

                    @Override
                    public void onVideoError(AdError adError) {
                        callInterstitialVideoError();
                    }

                    @Override
                    public void onVideoPageOpen() {

                    }

                    @Override
                    public void onVideoPageClose() {

                    }
                });
            }

            @Override
            public void onVideoCached() {

            }

            @Override
            public void onNoAD(AdError adError) {
                callLoadFailed(adError.getErrorCode(), adError.getErrorMsg());
            }

            @Override
            public void onADOpened() {

            }

            @Override
            public void onADExposure() {
                callInterstitialAdShow();
            }

            @Override
            public void onADClicked() {
                callInterstitialAdClick();
            }

            @Override
            public void onADLeftApplication() {

            }

            @Override
            public void onADClosed() {
                callInterstitialAdClose();
            }

            @Override
            public void onRenderSuccess() {

            }

            @Override
            public void onRenderFail() {

            }
        });
        interstitialAD.loadFullScreenAD();
    }

    @Override
    public void show(Activity activity) {
        if (this.interstitialAD != null) {
            interstitialAD.showFullScreenAD(activity);
        }
    }

    @Override
    public void destroy() {
        super.destroy();
        if (interstitialAD != null) {
            interstitialAD.destroy();
        }
    }
}
